package frontend.pages.admin.workplace;

import backend.model.admin.Workplace;
import backend.service.admin.WorkplaceService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.WorkplaceUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("workplace")
public class WorkplaceManagingPage extends AbstractManagingPage<Workplace> {

	public WorkplaceManagingPage() {
		super("pages.admin.workplace.title", "contextualHelp.admin.workplace.text");
	}

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.workplace.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.workplace.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.workplace.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new WorkplacePanel(panelId, getPageParameters(), new WorkplaceUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Workplace workplace) {
        getPageParameters().clearNamed();
        return new WorkplacePanel(panelId, null, new WorkplaceUIModel(workplace));
    }

    @Override
    public List<Workplace> loadAvailableEntities() {
        WorkplaceService workplaceService = TimeTrackingWebApplication.getService(WorkplaceService.class);
        return workplaceService.findAllWorkplaces();
    }
}
